import axios from '~/axios.js'

//上传文件
export function uploadFileApi(data, onUploadProgress) {
    return axios.post('/basic/file/uploadFile', data, {
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        onUploadProgress: (e) => {
            //获取上传进度
            if (onUploadProgress) {
                onUploadProgress(e)
            }
        }
    })
}

//删除文件 -> 根据文件URL删除
export function deleteFileApi(fileId) {
    return axios({
        method: 'DELETE',
        url: '/basic/file/deleteFile',
        params: {
            fileId: fileId
        }
    })
}

//获取文件列表 - 分页
export function getPageFileListApi(params) {
    return axios({
        method: 'GET',
        url: '/basic/file/getPageFileList',
        params: params
    })
}

export function downloadFileApi(fileId) {
    return axios({
        method: 'GET',
        url: `/basic/file/downloadFile/${fileId}`,
        responseType: 'blob' // 指定响应类型为blob
    })
}

/**
 * 批量删除文件
 * @param {Array} fileIds 文件ID数组
 * @returns {Promise}
 */
export function batchDeleteFileApi(fileIds) {
    return axios({
        url: '/basic/file/deleteBatchFiles',
        method: 'delete',
        params: {
            fileIds: fileIds // 直接传递数组，axios会自动处理为多个同名参数
        }
    });
}